/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AfficheFichierPanel.java
 *
 * Created on 29 févr. 2012, 09:49:32
 */
package fr.insa.glaizot;

import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;

/**
 *
 * @author 4glaitan
 */
public class AfficheFichierPanel extends javax.swing.JPanel {

    /** Creates new form AfficheFichierPanel */
    public AfficheFichierPanel() {
        initComponents();
    }

    public static void main(String[] args) {
        JFrame f = new JFrame("Lecture fichier");
        AfficheFichierPanel a = new AfficheFichierPanel();
        f.add(a);
        f.setSize(400, 300);
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.setVisible(true);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtfnom = new javax.swing.JTextField();
        jblire = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtatexte = new javax.swing.JTextArea();

        jtfnom.setText("jTextField1");

        jblire.setText("jButton1");
        jblire.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jblireActionPerformed(evt);
            }
        });

        jtatexte.setColumns(20);
        jtatexte.setRows(5);
        jScrollPane1.setViewportView(jtatexte);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtfnom, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                        .addComponent(jblire)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfnom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jblire))
                .addGap(36, 36, 36)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jblireActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jblireActionPerformed
        try {
            // TODO add your handling code here:
            //String s = this.jtfnom.getText();
            //File f = new File(s);
            JFileChooser fc = new JFileChooser();
            int returnVal = fc.showOpenDialog(this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                String contenu = ExempleFichier.litFichier(f);
                this.jtatexte.setText(contenu);
            }
            
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Erreur");
        }

    }//GEN-LAST:event_jblireActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jblire;
    private javax.swing.JTextArea jtatexte;
    private javax.swing.JTextField jtfnom;
    // End of variables declaration//GEN-END:variables
}
